# cmake_minimum_required(VERSION 3.15)

# set(MUDUO_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../build/release-install-cpp11)
# set(MUDUO_INCLUDE ${MUDUO_BASE_DIR}/include)
# set(MUDUO_LIB_DIR ${MUDUO_BASE_DIR}/lib)

# file(GLOB SERVER "${PROJECT_SOURCE_DIR}/server.cc") #源文件
# file(GLOB CLIENT "${PROJECT_SOURCE_DIR}/client.cc") #源文件

# #头文件位置
# # include_directories(${PROJECT_SOURCE_DIR} ${MUDUO_INCLUDE})

# set(CMAKE_CXX_STANDARD 17)

# find_package(Threads REQUIRED)

# add_executable(server ${SERVER})
# add_executable(client ${CLIENT})

# foreach(TARGET_NAME IN ITEMS server client)
    
# target_link_directories(${TARGET_NAME} PRIVATE
#     ${MUDUO_LIB_DIR}/muduo
#     ${PROJECT_SOURCE_DIR}
# )

# target_link_libraries(${TARGET_NAME}
#     muduo_net
#     muduo_base
#     Threads::Threads
#     jsoncpp
# )
# #target_link_libraries(${TARGET_NAME} pthread)
# #target_link_libraries(${TARGET_NAME} jsoncpp)

# endforeach()


cmake_minimum_required(VERSION 3.20)  # 支持 C++17 和现代语法
project(MuduoNetProject)

# #设置构建类型为debug
# set(CMAKE_BUILD_TYPE "Debug")

# 设置 C++17 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#设置debug的gdb
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -g -ggdb")
# # 为 Release 模式设置优化标志
# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall")


# find_package(Threads REQUIRED)

# 定义 Muduo 库路径（相对路径转绝对路径）
set(MUDUO_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../build/release-install-cpp11)
set(MUDUO_INCLUDE_DIR ${MUDUO_BASE_DIR}/include)
set(MUDUO_LIB_DIR ${MUDUO_BASE_DIR}/lib)

# 添加可执行文件
add_executable(server server.cc)
add_executable(client client.cc)
add_executable(reg_server reg_server.cc)

# 为所有目标统一配置依赖
foreach(TARGET_NAME IN ITEMS server client reg_server)
    # 添加头文件搜索路径
    target_include_directories(${TARGET_NAME} PRIVATE
        ${MUDUO_INCLUDE_DIR}  # Muduo 头文件
    )

    # 添加库搜索路径
    target_link_directories(${TARGET_NAME} PRIVATE
        ${MUDUO_LIB_DIR}      # Muduo 库位置
    )

    # 链接依赖库
    target_link_libraries(${TARGET_NAME} PRIVATE
        muduo_net             # 网络库
        muduo_base            # 基础库
        pthread     # 线程库（自动转换为 Threads::Threads）
        jsoncpp
    )

    # # 为每个目标单独设置调试属性 [7](@ref)
    # set_target_properties(${TARGET_NAME} PROPERTIES
    #     COMPILE_FLAGS "-g -ggdb"
    #     LINK_FLAGS "-g"
    # )
endforeach()

# 可选：添加清理扩展（支持 `cmake --build . --target clean`）
#set_property(DIRECTORY PROPERTY ADDITIONAL_CLEAN_FILES "server;client")